<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('用户列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<div class="select-list">
							<ul>
								<li>
									水电师傅：<select name="workerId" class="form-control" onchange="$.table.search()">
									<option value="">所有</option>
									<option th:each="worker:${workerList}" th:text="${worker.userName}" th:value="${worker.userId}"></option>
								</select>
								</li>
								<li>
									用户名称：<input type="text" name="userName" onkeyup="$.table.search()"/>
								</li>
								<li>
									手机号码：<input type="text" name="phonenumber" onkeyup="$.table.search()"/>
								</li>
								<li>
									用户状态：<select name="status" class="form-control" th:with="type=${@dict.getType('sys_normal_disable')}" onchange="$.table.search()">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
									</select>
								</li>
								<li>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;全部</a>
								</li>
							</ul>
						</div>
					</form>
				</div>
				
		        <div class="btn-group-sm" id="toolbar" role="group">
		        	<a class="btn btn-success" onclick="userAdd()">
		                <i class="fa fa-plus"></i> 新增
		            </a>
		        </div>
		        
		        <div class="col-sm-12 select-table table-striped">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: select2-js" />
	<script th:inline="javascript">

		$(function() {
		    var options = {
		        url: ctx + "hh/user/userList",
		        removeUrl: ctx + "system/user/remove",
				showSearch: false,
				showRefresh: false,
				showToggle: false,
				showColumns: false,
				modalName: "用户",
		        columns: [
		        {
		            field: 'userId',
		            title: '用户ID',
					visible: false
		        },
				{
					title: "序号",
					align: 'center',
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
		        {
		            field: 'userName',
		            title: '用户名称'
		        },
		        {
		            field: 'phonenumber',
		            title: '手机'
		        },
				{
					field: 'userAccount',
					title: '累欠金额'
				},
		        {
		        	title: '用户状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
				{
					field: 'remark',
					title: '备注',
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="userEdit(' + row.userId + ')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
			$.table.search();
		});

		$('#bootstrap-table').on('page-change.bs.table', function (e,number, size) {
			window.scrollTo(0,0);
		});

        /* 用户管理-新增 */
        function userAdd() {
            layer.open({
                type: 2,
                area: ['600px', '500px'],
                fix: false,
                shade: 0.3,
                title: '新增客户',
                content: ctx + "hh/user/userAdd",
                btn: [],
                end: function () {
                    $.table.refresh();
                }
            });
        }

        /* 用户管理-编辑信息 */
        function userEdit(userId) {
            layer.open({
                type: 2,
                area: ['600px', '500px'],
                fix: false,
                shade: 0.3,
                title: '修改信息',
                content: ctx + "hh/user/userEdit/" + userId,
                btn: [],
                end: function () {
                    $.table.refresh();
                }
            });
        }

		/* 用户状态显示 */
		function statusTools(row) {
			if (row.status == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
			}
		}

		/* 用户管理-停用 */
		function disable(userId) {
			$.modal.confirm("确认要停用用户吗？", function() {
				$.operate.post(ctx + "system/user/changeStatus", { "userId": userId, "status": 1 });
			})
		}

		/* 用户管理启用 */
		function enable(userId) {
			$.modal.confirm("确认要启用用户吗？", function() {
				$.operate.post(ctx + "system/user/changeStatus", { "userId": userId, "status": 0 });
			})
		}

		/* 用户管理-重置密码 */
		function resetPwd(userId) {
		    var url = prefix + '/resetPwd/' + userId;
		    $.modal.open("重置密码", url, '800', '300');
		}

	</script>
</body>
</html>